import uuid
import Postgres

class Node:
    """A node"""

    # class variable shared by all instances
    #kind = 'canine'         # example of class variable shared by all instances
    #Maybe should define activation functions here

    def __init__(self, label = None, value = None, bias = None):
        self.id = uuid.uuid4() # instance variable unique to each instance
        self.label = label
        self.value = value
        self.bias = bias
        self.subscribers = {}
        self.edges = []
        pass

    def __repr__(self):
        """
        Returns something that looks like
        label {0}\n
        value {0}\n
        bias  {0}\n
        edges {0}\n
        """
        return "label {0}\nvalue {1}\nbias  {2}\nedges {3}\n".format(
            self.label,
            self.value,
            self.bias,
            len(self.edges))
        pass

    def add_subscriber(self, node):
        self.subscribers[node.id] = node
        pass

    def add_edge(self, node=None, weight=None, label=None):
        e = Edge(node, weight, label)
        node.add_subscriber(self)
        self.edges.append(e)
        #recalculate value
        pass

class Edge:
    """An edge"""

    # class variable shared by all instances
    #kind = 'canine'         # example of class variable shared by all instances

    def __init__(self, node = None, weight = None, label = None):
        self.id = uuid.uuid4()
        self.label = label
        self.node = node
        self.weight = weight
        pass

    def __repr__(self):
        """
        Returns something that looks like
        label {0}\n
        value {0}\n
        bias  {0}\n
        edges {0}\n
        """
        return "label {0}\nvalue {1}\nbias  {2}\nedges {3}\n".format(
            self.label,
            self.value,
            self.bias,
            len(self.edges))
        pass

########################################################################################################################
if __name__ == '__main__':
    in0 = Node('in0', 1.0)
    in1 = Node('in1', 2.0)
    in2 = Node('in2', 3.0)

    hn0 = Node('hn0', None, -2.0)
    hn1 = Node('hn1', None, -6.0)
    hn2 = Node('hn2', None, -1.0)
    hn3 = Node('hn3', None, -7.0)


    #how do we describe that there is an edge between inX to hnX
    #hn0.edges.append(Edge(in0, 0.1))
    hn0.add_edge(in0, 0.1)
    hn0.add_edge(in1, 0.5)
    hn0.add_edge(in2, 0.9)

    hn1.add_edge(in0, 0.2)
    hn1.add_edge(in1, 0.6)
    hn1.add_edge(in2, 1.0)

    hn2.add_edge(in0, 0.3)
    hn2.add_edge(in1, 0.7)
    hn2.add_edge(in2, 1.1)

    hn3.add_edge(in0, 0.4)
    hn3.add_edge(in1, 0.8)
    hn3.add_edge(in2, 1.2)

    #--------------------------------------------------------------------------------
    #Postgres DB test
    #--------------------------------------------------------------------------------
    data = ["%Gary%"]
    rows = Postgres.etracks.get("SELECT * FROM student WHERE full_name LIKE %s;", data)
    for row in rows:
        print ">", row[1]

    print "========================================\r\n"
    data = ["S0000001Z" , "%Ong%"]
    cnt = Postgres.etracks.run("UPDATE student SET nationality_id = %s where full_name LIKE %s;", data)
    print "cnt:", cnt
